package com.example.myrecycyleview528zyr.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.widget.TextViewCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.MultiAutoCompleteTextView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.myrecycyleview528zyr.R;
import com.example.myrecycyleview528zyr.adapter.MyAdapter;
import com.example.myrecycyleview528zyr.bean.ArticleBean;
import com.example.myrecycyleview528zyr.iface.ArticleListener;
import com.example.myrecycyleview528zyr.model.ArticleModel;

import java.util.List;

import static com.example.myrecycyleview528zyr.R.attr.layoutManager;

/**
 * Created by jone on 2017/5/23.
 */
public class ArticleFragment extends Fragment {
   // private TextView tvinfo;
    private View view = null;
    private Context context;
    RecyclerView recyclerView;
    RecyclerView.LayoutManager layoutManager;
    MyAdapter myAdapter;
    List<ArticleBean>list=null;
    ArticleListener articleListener= new ArticleListener() {
        @Override
        public void onResponse(List<ArticleBean> list) {
            list=list;
            myAdapter.setList(list);
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(context,msg,Toast.LENGTH_SHORT).show();
        }
    };
    //    private static int cur_page=1;
//    private static int lastVisibleItemPosition;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        context = getActivity();
        view = inflater.inflate(R.layout.articlefragment, container, false);
        //tvinfo = (TextView) view.findViewById(R.id.textView5);
        //tvinfo.setText("微信");
        recyclerView=(RecyclerView)view.findViewById(R.id.recycleView);
        layoutManager=new LinearLayoutManager(context);
        recyclerView.setLayoutManager(layoutManager);
        myAdapter=new MyAdapter(context);
        myAdapter.setList(list);
        recyclerView.setAdapter(myAdapter);
        ArticleModel articleModel=new ArticleModel();
        articleModel.getResultList("article",2,"ctvi2efhtj6up1p3f5fvnfaeh7",articleListener);
        Toast.makeText(context, "加载fragment微信", Toast.LENGTH_SHORT).show();
        return view;
    }
}


